local hconfig = {}

hconfig.NET = {
    --透传平台使能位:0关闭 1收发 2只发 3只收
    ser = { { "112.74.100.65", "9999", 1 },
        { "119.23.134.117", "9450", 1 },
        { "",               "",     0 },
        { "",               "",     0 }, },
    reg = { 1, "123" },
    heart = { 0, "" },
}
hconfig.DEV_NUMBER = "81039999"
hconfig.COMPANY = "广州一洲信息技术有限公司"
hconfig.HPROJECT = "数据传输终端3.0"
hconfig.SVERSION = "DTU3.0_V1.0"
hconfig.MODI_DATA = "2024-09-06 21:18"
hconfig.IMEI = ""
hconfig.ADC_A = 22.162162162162
hconfig.ADC_B = -42.432432432435
hconfig.POWER_DATE = ""
hconfig.LED_MODE = 1
hconfig.RESTART_FLAG = 0  --是否重启标志
hconfig.RESTART_HOUR = 0  --重启时间点
hconfig.LAN_MODE = 0  --LAN模式开启标志
hconfig.STA_4G = 1  --0:关闭 1:4G优先 2:WiFi优先
hconfig.STA_SSID = ""
hconfig.STA_PSWD = ""

function hconfig.param_init()
    if not fskv.get("NET") then
        fskv.set("NET", hconfig.NET)
    end
    if not fskv.get("DEV_NUMBER") then
        fskv.set("DEV_NUMBER", hconfig.DEV_NUMBER)
    end
    if not fskv.get("COMPANY") then
        fskv.set("COMPANY", hconfig.COMPANY)
    end
    if not fskv.get("HPROJECT") then
        fskv.set("HPROJECT", hconfig.HPROJECT)
    end
    if not fskv.get("IMEI") then
        fskv.set("IMEI", hconfig.IMEI)
    end
    if not fskv.get("SVERSION") then
        fskv.set("SVERSION", hconfig.SVERSION)
    end
    if not fskv.get("MODI_DATA") then
        fskv.set("MODI_DATA", hconfig.MODI_DATA)
    end
    if not fskv.get("ADC_A") then
        fskv.set("ADC_A", hconfig.ADC_A)
    end
    if not fskv.get("ADC_B") then
        fskv.set("ADC_B", hconfig.ADC_B)
    end
    if not fskv.get("LED_MODE") then
        fskv.set("LED_MODE", hconfig.LED_MODE)
    end
    if not fskv.get("RESTART_FLAG") then
        fskv.set("RESTART_FLAG", hconfig.RESTART_FLAG)
    end
    if not fskv.get("RESTART_HOUR") then
        fskv.set("RESTART_HOUR", hconfig.RESTART_HOUR)
    end
    if not fskv.get("POWER_DATE") then
        fskv.set("POWER_DATE", hconfig.POWER_DATE)
    end
    if not fskv.get("LAN_MODE") then
        fskv.set("LAN_MODE", hconfig.LAN_MODE)
    end
    if not fskv.get("STA_4G") then
        fskv.set("STA_4G", hconfig.STA_4G)
    end
    if not fskv.get("STA_SSID") then
        fskv.set("STA_SSID", hconfig.STA_SSID)
    end
    if not fskv.get("STA_PSWD") then
        fskv.set("STA_PSWD", hconfig.STA_PSWD)
    end
end

function sys_flag_back(flag)
    if flag > 0 then
        return true
    else
        return false
    end
end

function hconfig.wifi_getparam()
    local param = {}
    param.DEV_NUMBER = hconfig.DEV_NUMBER
    param.HPROJECT = hconfig.HPROJECT
    param.IMEI = hconfig.IMEI
    param.ICCID = h485.Sensor_val.iccid
    param.SERVER1_FLAG = hconfig.NET.ser[1][3]==1 and true or false
    param.SERVER1 = hconfig.NET.ser[1][1]..":"..hconfig.NET.ser[1][2]
    if hconfig.NET.ser[1][1]=="" then
        param.SERVER1=""
    end
    param.SERVER2_FLAG = hconfig.NET.ser[2][3]==1 and true or false
    param.SERVER2 = hconfig.NET.ser[2][1]..":"..hconfig.NET.ser[2][2]
    if hconfig.NET.ser[2][1]=="" then
        param.SERVER2=""
    end
    param.SERVER3_FLAG = hconfig.NET.ser[3][3]==1 and true or false
    param.SERVER3 = hconfig.NET.ser[3][1]..":"..hconfig.NET.ser[3][2]
    if hconfig.NET.ser[3][1]=="" then
        param.SERVER3=""
    end
    param.SERVER4_FLAG = hconfig.NET.ser[4][3]==1 and true or false
    param.SERVER4 = hconfig.NET.ser[4][1]..":"..hconfig.NET.ser[4][2]
    if hconfig.NET.ser[4][1]=="" then
        param.SERVER4=""
    end
    param.REG_FLAG = hconfig.NET.reg[1]==1 and true or false
    param.REG = hconfig.NET.reg[2]
    param.HEART_FLAG = hconfig.NET.heart[1]==1 and true or false
    param.HEART = hconfig.NET.heart[2]
    param.NETMODE = hconfig.STA_4G
    param.LAN_MODE = hconfig.LAN_MODE
    
    return json.encode({data=param, ok=true})
end

return hconfig
